package logic

import (
	"context"
	"zhihu/models/mysql"

	"zhihu/zhihurpc/internal/svc"
	"zhihu/zhihurpc/zhihurpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AnswerAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAnswerAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AnswerAddLogic {
	return &AnswerAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AnswerAddLogic) AnswerAdd(in *zhihurpc.AnswerAddRequest) (*zhihurpc.AnswerAddResponse, error) {
	// todo: add your logic here and delete this line
	answer := mysql.Answer{
		Speak:     in.Speak,
		ProblemId: int(in.ProblemId),
		UserId:    int(in.UserId),
	}
	mysql.DB.Debug().Create(&answer)

	return &zhihurpc.AnswerAddResponse{
		Answer: int64(answer.ID),
	}, nil
}
